import { defineConfig } from 'vite';
import uni from "@dcloudio/vite-plugin-uni";
// import  { viteCommonjs }   from '@originjs/vite-plugin-commonjs';
 import path from 'path';
 import fs from 'fs-extra';
//插件用于把siteinfo.js文件拷贝到打包后的目录。
function copyFile() {
	return {
		enforce: 'post',
		async writeBundle() {
			await fs.copy(
				path.resolve(__dirname, 'siteinfo.js'),
				path.join(
					__dirname, 
					'unpackage/dist',
					process.env.NODE_ENV === 'production' ? 'build' : 'dev',
					process.env.UNI_PLATFORM,
					'siteinfo.js'
				)
			);
		},
	};
}
 
/**
 * @type {import('vite').UserConfig}
 */
export default defineConfig( {
   // 配置选项
    plugins:[
		uni(),  
		copyFile(),
	], 
 })